﻿using System;

namespace Fast
{
    /// <summary>
    /// 释放Action类
    /// </summary>
    [SkipScan]
    public class DisposeAction : IDisposable
    {
        private readonly Action _action;

        /// <summary>
        /// 创建一个新的 <see cref="DisposeAction"/> 对象
        /// </summary>
        /// <param name="action">释放时处理的动作</param>
        public DisposeAction(Action action)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            _action = action;
        }

        public void Dispose()
        {
            _action();
        }
    }
}
